#include<iostream>
#include<memory>
#include<string>
#include <windows.h>
using namespace std;

//抽象类处理者
class Handler {
    protected:
        shared_ptr<Handler> nextHandler;
    public:
        void setNext(shared_ptr<Handler> next) {
            nextHandler = next;
        }
        virtual void handleRequest(int days) = 0;
        virtual ~Handler() = default;
};

//具体处理者类A
class Supervisor : public Handler {
    public:
        void handleRequest(int days) override {
            if(days<=2){
                cout << "部门主管批准了 " << days << " 天请假。" << endl;
            }
            else if(nextHandler){
                cout << "部门主管：权限不够，转交上级处理..." << endl;
                nextHandler->handleRequest(days);
            }
        }
};

// 🎯 具体处理者B —— 经理
class Manager : public Handler
{
public:
    void handleRequest(int days) override
    {
        if (days <= 5)
        {
            cout << "经理批准了 " << days << " 天请假。" << endl;
        }
        else if (nextHandler)
        {
            cout << "经理：权限不够，转交总经理处理..." << endl;
            nextHandler->handleRequest(days);
        }
    }
};

// 🎯 具体处理者C —— 总经理
class GeneralManager : public Handler
{
public:
    void handleRequest(int days) override
    {
        if (days <= 10)
        {
            cout << "总经理批准了 " << days << " 天请假。" << endl;
        }
        else
        {
            cout << "❌ 请假天数太多，审批被拒绝！" << endl;
        }
    }
};

// 🎯 客户端（Client）
int main()
{
    SetConsoleOutputCP(65001);
    // 创建处理者
    auto supervisor = make_shared<Supervisor>();
    auto manager = make_shared<Manager>();
    auto generalManager = make_shared<GeneralManager>();

    // 建立责任链
    supervisor->setNext(manager);
    manager->setNext(generalManager);

    // 模拟请求
    cout << "员工申请 1 天假：" << endl;
    supervisor->handleRequest(1);

    cout << "\n员工申请 4 天假：" << endl;
    supervisor->handleRequest(4);

    cout << "\n员工申请 8 天假：" << endl;
    supervisor->handleRequest(8);

    cout << "\n员工申请 15 天假：" << endl;
    supervisor->handleRequest(15);

    return 0;
}